package demo.springboot.Tools;

public class Array_tools {

    //   删除指定索引的数组
    public static int[] remove(int[] arr , Integer index){
        int[] newArray = new int[arr.length - 1];// 新数组，长度为原始数组减去 1
        for (int i = 0; i < newArray.length; i++) {
            // 判断元素是否越界
            if (index < 0 || index >= arr.length) {
                throw new RuntimeException("元素越界... ");
            }
            //
            if (i < index) {
                newArray[i] = arr[i];
            } else {
                newArray[i] = arr[i + 1];
            }
        }
        return newArray;
    }
}
